package link.fls.swipestacksample;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import androidx.cardview.widget.CardView;
import androidx.core.content.ContextCompat;

import java.util.List;

/**
 * Created by zxn on 2021/11/24.
 */
public class SwipeStackAdapter extends BaseAdapter {

    private List<String> mData;

    public SwipeStackAdapter(List<String> data) {
        this.mData = data;
    }

    @Override
    public int getCount() {
        return mData.size();
    }

    @Override
    public String getItem(int position) {
        return mData.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {

        if (convertView == null) {
            convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.card, parent, false);
        }

        TextView textViewCard = convertView.findViewById(R.id.textViewCard);
        textViewCard.setText(mData.get(position));

        CardView cvBg = convertView.findViewById(R.id.cvBg);
        if (position == 0){
            cvBg.setCardBackgroundColor(ContextCompat.getColor(parent.getContext(),R.color.colorAccent));
        }else if (position == 2){
            cvBg.setCardBackgroundColor(ContextCompat.getColor(parent.getContext(),R.color.colorPrimary));
        }else {
            cvBg.setCardBackgroundColor(ContextCompat.getColor(parent.getContext(),R.color.colorGreen));
        }


        /*TextView tvTopIndex = convertView.findViewById(R.id.tvTopIndex);
        TextView tvCenterIndex = convertView.findViewById(R.id.tvCenterIndex);
        TextView tvBottomIndex = convertView.findViewById(R.id.tvBottomIndex);*/

        /*if (position == 0){
            tvTopIndex.setVisibility(View.VISIBLE);

            tvCenterIndex.setVisibility(View.GONE);
            tvBottomIndex.setVisibility(View.GONE);
        }else if (position == 1){
            tvCenterIndex.setVisibility(View.VISIBLE);

            tvTopIndex.setVisibility(View.GONE);
            tvBottomIndex.setVisibility(View.GONE);
        }else if (position == 2){
            tvBottomIndex.setVisibility(View.VISIBLE);

            tvTopIndex.setVisibility(View.GONE);
            tvCenterIndex.setVisibility(View.GONE);
        }else{
            tvBottomIndex.setVisibility(View.GONE);
            tvTopIndex.setVisibility(View.GONE);
            tvCenterIndex.setVisibility(View.GONE);
        }*/
        return convertView;
    }
}
